﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;
using Model;
using gfLibrary;
using System.Drawing;
using System.Data;
using IYAKASAPortal.Services;
using System.Xml.Linq;
using System.IO;
using System.Xml;
using System.Web.UI.WebControls;
using System.Web.UI;
using UtilityHelper;
using System.Text.RegularExpressions;
using System.Reflection;

namespace IYAKASAPortal.Login
{
    public static class LoginHelper
    {
        public struct ControlNames
        {
            public string Name;
            public string Value;
            public ControlNames(string name, string value)
            {
                Name = name;
                Value = value;
            }

        }

        /// <summary>
        /// 得到品牌型号
        /// </summary>
        /// <param name="content"></param>
        /// <param name="lstNames"></param>
        /// <param name="lstControls"></param>
        public static void GetPPXH(TYPE_CX_CONTENT content, List<ControlNames> lstNames, List<Control> lstControls)
        {
            Type t = content.GetType();
            var lstProperties = t.GetProperties();

            foreach (var v in lstProperties)
            {
                for (int i = 0; i < lstNames.Count; i++)
                {
                    var con = lstControls.Where(x => x.ID == lstNames[i].Name).ToList();
                    if (con.Count > 0)
                    {
                        if (v.Name == lstNames[i].Value)
                        {
                            if (lstNames[i].Name.Substring(0, 3) == "txt")
                            {
                                try
                                {
                                    TextBox txt = con[0] as TextBox;
                                    txt.Text = v.GetValue(content, null).ToString();
                                }
                                catch (Exception ex) { }
                                break;
                            }
                            else if (lstNames[i].Name.Substring(0, 3) == "drp")
                            {
                                try
                                {
                                    DropDownList drp = con[0] as DropDownList;
                                    string strControlValue = v.GetValue(content, null).ToString();
                                    if (!string.IsNullOrEmpty(strControlValue))
                                    {
                                        drp.SelectedValue = strControlValue;
                                    }
                                }
                                catch (Exception ex) { }
                                break;
                            }
                            else if (lstNames[i].Name.Substring(0, 4) == "rbtn")
                            {
                                try
                                {
                                    RadioButtonList rbtn = con[0] as RadioButtonList;
                                    string strControlValue = v.GetValue(content, null).ToString();
                                    if (!string.IsNullOrEmpty(strControlValue))
                                    {
                                        rbtn.SelectedValue = strControlValue;
                                    }
                                }
                                catch (Exception ex) { }
                                break;
                            }
                            else if (lstNames[i].Name.Substring(0, 3) == "chk")
                            {
                                try
                                {
                                    CheckBoxList chkList = con[0] as CheckBoxList;

                                    string strValues = v.GetValue(content, null).ToString();
                                    if (string.IsNullOrEmpty(strValues) == false)
                                    {
                                        strValues = strValues.Substring(0, strValues.Length - 1);
                                        if (strValues.Contains(","))
                                        {
                                            string[] strLst = strValues.Split(',');
                                            for (int k = 0; k < chkList.Items.Count; k++)
                                            {
                                                foreach (var s in strLst)
                                                {
                                                    if (chkList.Items[k].Value == s)
                                                    {
                                                        chkList.Items[k].Selected = true;
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            for (int k = 0; k < chkList.Items.Count; k++)
                                            {
                                                if (chkList.Items[k].Value == strValues)
                                                {
                                                    chkList.Items[k].Selected = true;
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex) { }
                                break;
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 得到发动机型号
        /// </summary>
        /// <param name="content"></param>
        /// <param name="lstNames"></param>
        /// <param name="lstControls"></param>
        public static void GetFDJXH(TYPE_FDJ_CONTENT content, List<ControlNames> lstNames, List<Control> lstControls)
        {
            Type t = content.GetType();
            var lstProperties = t.GetProperties();

            foreach (var v in lstProperties)
            {
                for (int i = 0; i < lstNames.Count; i++)
                {
                    var con = lstControls.Where(x => x.ID == lstNames[i].Name).ToList();
                    if (con.Count > 0)
                    {
                        if (v.Name == lstNames[i].Value)
                        {
                            if (lstNames[i].Name.Substring(0, 3) == "txt")
                            {
                                try
                                {
                                    TextBox txt = con[0] as TextBox;
                                    txt.Text = v.GetValue(content, null).ToString();
                                }
                                catch (Exception ex) { }
                                break;
                            }
                            else if (lstNames[i].Name.Substring(0, 3) == "drp")
                            {
                                try
                                {
                                    DropDownList drp = con[0] as DropDownList;
                                    string strControlValue = v.GetValue(content, null).ToString();
                                    if (!string.IsNullOrEmpty(strControlValue))
                                    {
                                        drp.SelectedValue = strControlValue;
                                    }
                                }
                                catch (Exception ex) { }
                                break;
                            }
                            else if (lstNames[i].Name.Substring(0, 4) == "rbtn")
                            {
                                try
                                {
                                    RadioButtonList rbtn = con[0] as RadioButtonList;
                                    string strControlValue = v.GetValue(content, null).ToString();
                                    if (!string.IsNullOrEmpty(strControlValue))
                                    {
                                        rbtn.SelectedValue = strControlValue;
                                    }
                                }
                                catch (Exception ex) { }
                                break;
                            }
                            else if (lstNames[i].Name.Substring(0, 3) == "chk")
                            {
                                try
                                {
                                    CheckBoxList chkList = con[0] as CheckBoxList;

                                    string strValues = v.GetValue(content, null).ToString();
                                    if (string.IsNullOrEmpty(strValues) == false)
                                    {
                                        strValues = strValues.Substring(0, strValues.Length - 1);
                                        if (strValues.Contains(","))
                                        {
                                            string[] strLst = strValues.Split(',');
                                            for (int k = 0; k < chkList.Items.Count; k++)
                                            {
                                                foreach (var s in strLst)
                                                {
                                                    if (chkList.Items[k].Value == s)
                                                    {
                                                        chkList.Items[k].Selected = true;
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            for (int k = 0; k < chkList.Items.Count; k++)
                                            {
                                                if (chkList.Items[k].Value == strValues)
                                                {
                                                    chkList.Items[k].Selected = true;
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex) { }
                                break;
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 得到当前状态
        /// </summary>
        /// <param name="info"></param>
        /// <param name="strType"></param>
        /// <param name="JCLSH"></param>
        /// <returns></returns>
        public static bool GetTestStatus(LOGIN_VEHICLE_INFO info, string strType, out string JCLSH)
        {
            bool bUpdate = true;
            VEHICLE_DISPATCH_BLL bll = new VEHICLE_DISPATCH_BLL();
            var vLst = bll.GetModelList("VEHICLEID='" + info.VEHICLEID + "' and subString(JCLSH,1,1)='" + strType + "' and JCZT_STATUS=0 and SUBSTRING(DLRQ,1,10)=(Datename(year,GetDate())+'-'+Datename(month,GetDate())+'-'+Datename(day,GetDate())) order by ID desc");
            if (vLst.Length > 0)
            {
                bUpdate = true;
                JCLSH = vLst[0].JCLSH;
            }
            else
            {
                JCLSH = "";
                bUpdate = false;
            }
            return bUpdate;
        }

        /// <summary>
        /// 生成检测流水号
        /// </summary>
        /// <param name="info">车辆信息</param>
        /// <param name="JCCS">检测次数</param>
        /// <param name="strType">检测类型，A-安检，Z-综检，P-环检</param>
        /// <param name="bIsFirstTest">是否为初检</param>
        /// <returns></returns>
        public static string GenerateJCLSH(LOGIN_VEHICLE_INFO info, out int JCCS, string strType, bool bIsFirstTest)
        {
            string JCLSH = "";
            string strHPZL = "P";
            if (info.HPZLDH == "15")
            {
                strHPZL = "G";
            }

            string strDate = DateTime.Now.ToString("yyyyMMddHHmmss");

            int Code = GetLoginCount(strType);

            string strCode = Code.ToString("0000");

            string strSql = "select JCLSH,CLSXSJ from [VEHICLE_DISPATCH] where HPHM='" + info.HPHM + "' and HPZLDH='" + info.HPZLDH + "' and subString(JCLSH,1,1)='" + strType + "' order by ID desc";
            DataTable dt = new DataTable();
            DBUtility.DbHelper.GetTable(strSql, ref dt);

            int Count = 1;
            if (dt.Rows.Count > 0)
            {
                if (bIsFirstTest)
                {
                    Count = 1;
                    string strCount = Count.ToString("00");
                    JCLSH = strType + strDate.Substring(2, 6) + strHPZL + "9" + strDate.Substring(8, 6) + strCode + "-" + strCount;
                    JCCS = Count;
                }
                else
                {
                    Count = Convert.ToInt32(dt.Rows[0]["JCLSH"].ToString().Split('-')[1]) + 1;
                    string strPLSH = dt.Rows[0]["JCLSH"].ToString();
                    JCLSH = strPLSH.Substring(0, strPLSH.Length - 2) + Count.ToString("00");
                    JCCS = Count;
                }
            }
            else
            {
                Count = 1;
                string strCount = Count.ToString("00");
                JCLSH = strType + strDate.Substring(2, 6) + strHPZL + "9" + strDate.Substring(8, 6) + strCode + "-" + strCount;
                JCCS = Count;
            }

            return JCLSH;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <param name="strZC_JCLSH">主车流水号</param>
        /// <param name="strGLCJCLSH">关联车流水号 hid</param>
        /// <param name="bTogether">chkTogether</param>
        /// <param name="strType">安检 A ,综检 Z</param>
        /// <param name="bFirstTest">rbtnFirst</param>
        /// <returns></returns>
        public static bool UpdateGCInfo(LOGIN_VEHICLE_INFO info, string strZC_JCLSH, string strGLCJCLSH, bool bTogether, string strType, bool bFirstTest)
        {
            try
            {
                VEHICLE_DISPATCH_BLL disBll = new VEHICLE_DISPATCH_BLL();
                VEHICLE_DISPATCH modelGC = new VEHICLE_DISPATCH();

                if (string.IsNullOrEmpty(strGLCJCLSH))//以前不是挂车
                {
                    if (bTogether && !string.IsNullOrEmpty(info.GLCHPHM))
                    {//列车一起发送
                        LOGIN_VEHICLE_INFO_BLL login_bll = new LOGIN_VEHICLE_INFO_BLL();
                        var login = login_bll.GetModelList("VEHICLEID='15" + info.GLCHPHM + "'");
                        if (login.Length > 0)
                        {
                            modelGC.VEHICLEID = login[0].VEHICLEID;
                            modelGC.JCZT_STATUS = 0;

                            int JCCS;
                            modelGC.JCLSH = GenerateJCLSH(login[0], out JCCS, strType, bFirstTest);
                            modelGC.JCCS = JCCS;

                            modelGC.JYXM = login[0].JYXM;
                            modelGC.HPHM = login[0].HPHM;
                            modelGC.HPZL = login[0].HPZL;
                            modelGC.HPZLDH = login[0].HPZLDH;
                            modelGC.CLZLDH = login[0].CLZLDH;
                            modelGC.VIN = login[0].VIN;
                            modelGC.JYLB = login[0].JYLB;
                            modelGC.JYLBDH = login[0].JYLBDH;
                            modelGC.DLY = login[0].DLY;
                            modelGC.GLCJCLSH = strZC_JCLSH;
                            modelGC.SFSQCLC = "1";
                            modelGC.GLCHPHM = login[0].HPHM;
                            modelGC.GLCHPZL = login[0].HPZL;
                            modelGC.GLCHPZLDH = login[0].HPZLDH;

                            disBll.Insert(modelGC);

                            var Zmodle = new VEHICLE_DISPATCH();
                            Zmodle.GLCJCLSH = modelGC.JCLSH;
                            Zmodle.GLCHPHM = modelGC.HPHM;
                            Zmodle.GLCHPZL = modelGC.HPZL;
                            Zmodle.GLCHPZLDH = modelGC.HPZLDH;
                            Zmodle.SFSQCLC = "1";
                            disBll.Update(Zmodle, strZC_JCLSH);
                        }
                    }
                }
                else
                {//以前是列车（带挂车）
                    if (bTogether && !string.IsNullOrEmpty(info.GLCHPHM))
                    {//列车一起发送
                        LOGIN_VEHICLE_INFO_BLL login_bll = new LOGIN_VEHICLE_INFO_BLL();
                        var login = login_bll.GetModelList("VEHICLEID='15" + info.GLCHPHM + "'");
                        if (login.Length > 0)
                        {
                            modelGC = disBll.GetModel(strGLCJCLSH);
                            modelGC.VEHICLEID = login[0].VEHICLEID;
                            modelGC.JCZT_STATUS = 0;
                            modelGC.JYXM = login[0].JYXM;
                            modelGC.HPHM = login[0].HPHM;
                            modelGC.HPZL = login[0].HPZL;
                            modelGC.HPZLDH = login[0].HPZLDH;
                            modelGC.CLZLDH = login[0].CLZLDH;
                            modelGC.VIN = login[0].VIN;
                            modelGC.JYLB = login[0].JYLB;
                            modelGC.JYLBDH = login[0].JYLBDH;
                            modelGC.DLY = login[0].DLY;
                            modelGC.GLCJCLSH = strZC_JCLSH;
                            modelGC.SFSQCLC = "1";
                            modelGC.GLCHPHM = login[0].HPHM;
                            modelGC.GLCHPZL = login[0].HPZL;
                            modelGC.GLCHPZLDH = login[0].HPZLDH;

                            disBll.Insert(modelGC);

                            var Zmodle = new VEHICLE_DISPATCH();
                            Zmodle.GLCJCLSH = modelGC.JCLSH;
                            Zmodle.GLCHPHM = modelGC.HPHM;
                            Zmodle.GLCHPZL = modelGC.HPZL;
                            Zmodle.GLCHPZLDH = modelGC.HPZLDH;
                            Zmodle.SFSQCLC = "1";
                            disBll.Update(Zmodle, strZC_JCLSH);
                        }
                    }
                    else
                    {//去除挂车，只发主车
                        modelGC = disBll.GetModel(strGLCJCLSH);
                        var GModel = new VEHICLE_DISPATCH(); //挂车
                        var ZModel = new VEHICLE_DISPATCH();  //主车
                        GModel.GLCJCLSH = "";
                        GModel.SFSQCLC = "0";
                        GModel.GLCHPHM = "";
                        GModel.GLCHPZL = "";
                        GModel.GLCHPZLDH = "";

                        ZModel.GLCJCLSH = "";
                        ZModel.SFSQCLC = "0";
                        ZModel.GLCHPHM = "";
                        ZModel.GLCHPZL = "";
                        ZModel.GLCHPZLDH = "";
                        disBll.Update(GModel, modelGC.JCLSH);
                        disBll.Update(ZModel, modelGC.GLCJCLSH);
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="login_info"></param>
        /// <param name="lstNames"></param>
        /// <param name="lstControls"></param>
        public static void LoadData(LOGIN_VEHICLE_INFO login_info, List<ControlNames> lstNames, List<Control> lstControls)
        {
            try
            {
                Type t = login_info.GetType();
                var lstProperties = t.GetProperties();

                foreach (var v in lstProperties)
                {
                    for (int i = 0; i < lstNames.Count; i++)
                    {
                        var con = lstControls.Where(x => x.ID == lstNames[i].Name).ToList();
                        if (con.Count > 0)
                        {
                            if (v.Name == lstNames[i].Value)
                            {
                                if (lstNames[i].Name.Substring(0, 3) == "txt")
                                {
                                    try
                                    {
                                        TextBox txt = con[0] as TextBox;
                                        string strValue = v.GetValue(login_info, null).ToString();
                                        if (txt.ID == "txtHPHM" || txt.ID == "txtHPHMGC")
                                        {
                                            txt.Text = strValue.Substring(2, strValue.Length - 2);
                                        }
                                        else if (txt.ID == "txtHPHMStart" || txt.ID == "txtHPHMStartGC")
                                        {
                                            txt.Text = strValue.Substring(0, 2);
                                        }
                                        else
                                        {
                                            txt.Text = strValue;
                                        }
                                    }
                                    catch (Exception ex) { }
                                    break;
                                }
                                else if (lstNames[i].Name.Substring(0, 3) == "drp")
                                {
                                    try
                                    {
                                        DropDownList drp = con[0] as DropDownList;
                                        string strControlValue = v.GetValue(login_info, null).ToString();
                                        if (!string.IsNullOrEmpty(strControlValue))
                                        {
                                            drp.SelectedValue = strControlValue;
                                        }
                                    }
                                    catch (Exception ex) { }
                                    break;
                                }
                                else if (lstNames[i].Name.Substring(0, 4) == "rbtn")
                                {
                                    try
                                    {
                                        RadioButtonList rbtn = con[0] as RadioButtonList;
                                        string strControlValue = v.GetValue(login_info, null).ToString();
                                        if (!string.IsNullOrEmpty(strControlValue))
                                        {
                                            rbtn.SelectedValue = strControlValue;
                                        }
                                    }
                                    catch (Exception ex) { }
                                    break;
                                }
                                else if (lstNames[i].Name.Substring(0, 3) == "chk")
                                {
                                    try
                                    {
                                        CheckBoxList chkList = con[0] as CheckBoxList;
                                        string strId = chkList.ID;
                                        for (int z = 0; z < chkList.Items.Count; z++)
                                        {
                                            chkList.Items[z].Selected = false;
                                        }

                                        string strValues = v.GetValue(login_info, null).ToString();
                                        if (string.IsNullOrEmpty(strValues) == false)
                                        {
                                            strValues = strValues.Substring(0, strValues.Length - 1);
                                            if (strValues.Contains(","))
                                            {
                                                string[] strLst = strValues.Split(',');
                                                for (int k = 0; k < chkList.Items.Count; k++)
                                                {
                                                    if (strValues.Contains(chkList.Items[k].Value))
                                                    {
                                                        chkList.Items[k].Selected = true;
                                                    }
                                                    else
                                                    {
                                                        chkList.Items[k].Selected = false;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                for (int k = 0; k < chkList.Items.Count; k++)
                                                {
                                                    chkList.Items[k].Selected = false;
                                                    if (chkList.Items[k].Value == strValues)
                                                    {
                                                        chkList.Items[k].Selected = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex) { }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string strError = ex.Message;
            }
        }

        /// <summary>
        /// 根据号牌号码和号牌种类得到Login Info
        /// </summary>
        /// <param name="strHPHM"></param>
        /// <param name="strHPZLDH"></param>
        /// <returns></returns>
        public static LOGIN_VEHICLE_INFO GetLoginInfo(string strHPHM, string strHPZLDH)
        {
            LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();
            var info = bll.GetModelList("VEHICLEID='" + strHPZLDH + strHPHM + "'");

            if (info.Length > 0)
            {
                return info[0];
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到当天的登录数量
        /// </summary>
        /// <param name="strType"></param>
        /// <returns></returns>
        public static int GetLoginCount(string strType)
        {
            int iCount = 1;
            string dtNow = DateTime.Now.ToString("yyyy-MM-dd");

            PUSH_LSH_COUNT_BLL bll = new PUSH_LSH_COUNT_BLL();
            var vInfo = bll.GetModelList("Test_Date='" + dtNow + "' and Test_type='" + strType + "' order by LSH_COUNT desc" );

            if (vInfo.Length > 0)
            {
                iCount = Convert.ToInt32(vInfo[0].LSH_COUNT) +1;
            }

            PUSH_LSH_COUNT m_PUSH_LSH_COUNT = new PUSH_LSH_COUNT();
            m_PUSH_LSH_COUNT.COUNT_TYPE = 0;
            m_PUSH_LSH_COUNT.LOGIN_PC_NO = "1";
            m_PUSH_LSH_COUNT.TEST_DATE = dtNow;
            m_PUSH_LSH_COUNT.LSH_COUNT = iCount.ToString();
            m_PUSH_LSH_COUNT.UPDATE_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            m_PUSH_LSH_COUNT.TEST_TYPE = strType;

            bll.Insert(m_PUSH_LSH_COUNT);

            return iCount;
        }

        /// <summary>
        /// 得到当天的登录数量
        /// </summary>
        /// <param name="strType"></param>
        /// <returns></returns>
        public static int GetCurrentDayLoginCount(string strType)
        {
            string strSql = "select count(*) from [VEHICLE_DISPATCH] where subString(JCLSH,1,1)='" + strType + "' and DLRQ>'" + DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:01' and DLRQ<'" + DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59'";
            int Code = Convert.ToInt32(DBUtility.DbHelper.GetValue(strSql)) + 1;

            return Code;
        }

        /// <summary>
        /// 确定是初检还是复检
        /// </summary>
        /// <param name="login"></param>
        /// <param name="rbtn"></param>
        public static void ConfirmJCXS(LOGIN_VEHICLE_INFO login, string strType, RadioButtonList rbtn, Label lblJCCS, out string strJCXM)
        {
            RESULT_VEHICLE_INFO_BLL bll = new RESULT_VEHICLE_INFO_BLL();
            var info = bll.GetModelList("HPHM='" + login.HPHM + "' and HPZLDH='" + login.HPZLDH + "' and substring(JCLSH,1,1)='" + strType + "' order by ID desc");

            bool bPass = false; //是否为初检
            string strFJXM = ""; //复检项目
            strJCXM = "";
            if (info.Length > 0)
            {
                if (info[0].JCCS != null)
                {
                    lblJCCS.Text = (info[0].JCCS).ToString();
                }

                if (string.IsNullOrEmpty(info[0].FJXM))
                {
                    bPass = true;
                }
                else
                {
                    strFJXM = info[0].FJXM;
                    string JCLSH = info[0].JCLSH.Split('-')[0] + "-01";
                    var vFirstInfo = bll.GetModel(JCLSH);

                    if (!string.IsNullOrEmpty(vFirstInfo.JCRQ))
                    {
                        CONST_DEFINE_WEB_BLL con_bll = new CONST_DEFINE_WEB_BLL();
                        var con = con_bll.GetModelList("CategoryID=3");
                        if (con.Length > 0)
                        {
                            if (Convert.ToDateTime(vFirstInfo.JCRQ).AddMonths(Convert.ToInt32(con[0].ValueOfName)) < DateTime.Now)
                            {
                                bPass = true;
                            }
                        }
                    }
                }
            }
            else
            {
                lblJCCS.Text = "0";
                bPass = true;
            }

            if (!bPass)
            {
                strJCXM = strFJXM;
                if(strJCXM.Contains("Z1,"))
                {
                    strJCXM = strJCXM.Replace("Z1,","");
                }
                else if (strJCXM.Contains("Z2,"))
                {
                    strJCXM = strJCXM.Replace("Z2,", "");
                }
                else if (strJCXM.Contains("Z2,"))
                {
                    strJCXM = strJCXM.Replace("Z2,", "");
                }
                else if (strJCXM.Contains("Z2,"))
                {
                    strJCXM = strJCXM.Replace("Z2,", "");
                }
            }

            rbtn.SelectedValue = (bPass ? "0" : "1");
        }

        /// <summary>
        /// 得到车辆状态
        /// </summary>
        /// <param name="strVehicleID"></param>
        /// <returns></returns>
        public static bool GetVehicleStatus(string strVehicleID)
        {
            bool bOngoing = false;
            VEHICLE_DISPATCH_BLL bll_Dis = new VEHICLE_DISPATCH_BLL();
            var dispatch = bll_Dis.GetModelList("VEHICLEID = '" + strVehicleID + "'");
            if (dispatch.Length > 0)
            {

                foreach (var v in dispatch)
                {
                    if (v.JCZT_STATUS > 0 && v.JCZT_STATUS < 4)
                    {
                        bOngoing = true;
                        break;
                    }
                }
            }

            return bOngoing;
        }

        /// <summary>
        /// 绑定检测项目
        /// </summary>
        /// <param name="info"></param>
        /// <param name="chk"></param>
        /// <param name="lstItems"></param>
        public static void BindJYXM(string strJYXM, CheckBoxList chk, List<ListItem> lstItems)
        {
            if (lstItems != null)
            {
                lstItems.All(x => x.Selected = false);

                List<string> lstSelected = new List<string>();
                if (!string.IsNullOrEmpty(strJYXM))
                {
                    if (strJYXM.Contains(","))
                    {
                        string[] strAry = strJYXM.Split(',');
                        foreach (var v in strAry)
                        {
                            lstSelected.Add(v);
                        }
                    }
                    else
                    {
                        lstSelected.Add(strJYXM);
                    }

                    foreach (var vSelected in lstSelected)
                    {
                        foreach (var vItem in lstItems)
                        {
                            if (vSelected == vItem.Value)
                            {
                                vItem.Selected = true;
                            }
                        }
                    }

                    for (int i = 0; i < chk.Items.Count; i++)
                    {
                        chk.Items[i].Selected = false;
                        foreach (var v in lstSelected)
                        {
                            if (chk.Items[i].Value == v)
                            {
                                chk.Items[i].Selected = true;
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 绑定综检挂车检测项目
        /// </summary>
        /// <param name="zzs"></param>
        /// <param name="chkJYXMGC"></param>
        /// <param name="lstItemsGC"></param>
        public static void BindJCXMGC_ZJ(int zzs, CheckBoxList chkJYXMGC, List<ListItem> lstItemsGC)
        {
            int iZZS = zzs;
            chkJYXMGC.Items.Clear();

            for (int i = 0; i < lstItemsGC.Count; i++)
            {
                if (lstItemsGC[i].Value.Substring(0, 1) == "B" || lstItemsGC[i].Value.Substring(0, 1) == "Z")
                {
                    if (Convert.ToInt32(lstItemsGC[i].Value.Substring(1, 1)) <= iZZS || lstItemsGC[i].Value == "B9")
                    {
                        chkJYXMGC.Items.Add(lstItemsGC[i]);
                    }
                }
                else
                {
                    chkJYXMGC.Items.Add(lstItemsGC[i]);
                }
            }
        }

        /// <summary>
        /// 根据Login_INFO表中ID得到DISPATCH中相关信息，并且返回是否已经存在
        /// </summary>
        /// <param name="strLoginID"></param>
        /// <param name="bIsFirstTest"></param>
        /// <param name="bIsUpdateDisPatch"></param>
        /// <returns></returns>
        public static VEHICLE_DISPATCH GetDispathchByLoginID(string strLoginID, string strType, bool bIsFirstTest, out bool bIsUpdateDisPatch)
        {
            LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();
            var info = bll.GetModel(Convert.ToInt32(strLoginID));

            VEHICLE_DISPATCH model = new VEHICLE_DISPATCH();
            model.VEHICLEID = info.VEHICLEID;
            model.JCZT_STATUS = 0;

            string strJCLSH;
            bool bIsUpdate = LoginHelper.GetTestStatus(info, strType, out strJCLSH);
            bIsUpdateDisPatch = bIsUpdate;

            if (bIsUpdate)
            {
                model.JCLSH = strJCLSH;
            }
            else
            {
                int JCCS;
                model.JCLSH = LoginHelper.GenerateJCLSH(info, out JCCS, strType, bIsFirstTest);
                model.JCCS = JCCS;
            }

            model.JYXM = info.JYXM;
            model.HPHM = info.HPHM;
            model.HPZL = info.HPZL;
            model.HPZLDH = info.HPZLDH;
            model.CLZLDH = info.CLZLDH;
            model.VIN = info.VIN;
            model.JYLB = info.JYLB;
            model.JYLBDH = info.JYLBDH;
            model.GW_STATUS = 0;
            model.DLY = GetLoginedUserName();
            model.GXRQ = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            model.DLRQ = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            if (strType == "A")
            {
                model.AJLSH = info.AJLSH;
            }
            if (strType == "Z")
            {

                model.ZJLSH = "370823" + "000" + DateTime.Now.ToString("yyyyMMdd") + GetCurrentDayLoginCount(strType).ToString("0000");
            }

            return model;
        }

        /// <summary>
        /// 检查所有需要输入的textbox，以及输入是否正确
        /// </summary>
        /// <param name="strLoginID"></param>
        /// <param name="strType"></param>
        /// <returns></returns>
        public static Dictionary<string, List<string>> CheckAllInputItems(string strLoginID, string strLoginIDGC, string strType)
        {
            Dictionary<string, List<string>> dicRet = new Dictionary<string, List<string>>();
            LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();
            if (strType == "A")
            {
                #region 安检主车
                if (string.IsNullOrEmpty(strLoginID) == false)
                {
                    var info = bll.GetModel(Convert.ToInt32(strLoginID));
                    if (info.ID > 0)
                    {
                        List<string> lst = new List<string>();
                        if (string.IsNullOrEmpty(info.VIN))
                        {
                            lst.Add("txtVIN");
                        }

                        if (string.IsNullOrEmpty(info.SYR))
                        {
                            lst.Add("txtSYR");
                        }

                        if (string.IsNullOrEmpty(info.LXDZ))
                        {
                            lst.Add("txtAddress");
                        }

                        if (string.IsNullOrEmpty(info.PP))
                        {
                            lst.Add("txtPP");
                        }

                        if (string.IsNullOrEmpty(info.XH))
                        {
                            lst.Add("txtXH");
                        }

                        if (string.IsNullOrEmpty(info.FDJH))
                        {
                            lst.Add("txtFDJNumber");
                        }

                        if (string.IsNullOrEmpty(info.CCDJRQ))
                        {
                            lst.Add("txtCSDJRQ");
                        }

                        if (string.IsNullOrEmpty(info.CYS))
                        {
                            lst.Add("txtHZRS");
                        }

                        if (string.IsNullOrEmpty(info.ZZL))
                        {
                            lst.Add("txtZZL");
                        }

                        if (string.IsNullOrEmpty(info.ZBZL))
                        {
                            lst.Add("txtZBZL");
                        }

                        if (string.IsNullOrEmpty(info.CSC))
                        {
                            lst.Add("txtWKCCC");
                        }

                        if (string.IsNullOrEmpty(info.CSK))
                        {
                            lst.Add("txtWKCCK");
                        }

                        if (string.IsNullOrEmpty(info.CSG))
                        {
                            lst.Add("txtWKCCG");
                        }

                        if (string.IsNullOrEmpty(info.ZGSJCS))
                        {
                            lst.Add("txtZGSJCS");
                        }

                        if (string.IsNullOrEmpty(info.LJXSLC))
                        {
                            lst.Add("txtLJXSLC");
                        }

                        dicRet.Add("A", lst);
                    }
                }
                #endregion

                #region 安检挂车
                if (string.IsNullOrEmpty(strLoginIDGC) == false)
                {
                    var infoGC = bll.GetModel(Convert.ToInt32(strLoginIDGC));
                    if (infoGC.ID > 0)
                    {
                        List<string> lst = new List<string>();
                        if (string.IsNullOrEmpty(infoGC.VIN))
                        {
                            lst.Add("txtVINGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.SYR))
                        {
                            lst.Add("txtSYRGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.LXDZ))
                        {
                            lst.Add("txtAddressGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.PP))
                        {
                            lst.Add("txtPPGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.XH))
                        {
                            lst.Add("txtXHGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.CCDJRQ))
                        {
                            lst.Add("txtCCDJRQGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.ZZL))
                        {
                            lst.Add("txtZZLGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.ZBZL))
                        {
                            lst.Add("txtZBZLGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.CSC))
                        {
                            lst.Add("txtCSCGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.CSK))
                        {
                            lst.Add("txtCSKGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.CSG))
                        {
                            lst.Add("txtCSGGC");
                        }

                        dicRet.Add("AG", lst);
                    }
                }
                #endregion
            }
            else if (strType == "Z")
            {
                #region 综检主车
                if (string.IsNullOrEmpty(strLoginID) == false)
                {
                    var info = bll.GetModel(Convert.ToInt32(strLoginID));
                    if (info.ID > 0)
                    {
                        List<string> lst = new List<string>();
                        if (string.IsNullOrEmpty(info.VIN))
                        {
                            lst.Add("txtVIN");
                        }

                        if (string.IsNullOrEmpty(info.SYR))
                        {
                            lst.Add("txtSYR");
                        }

                        if (string.IsNullOrEmpty(info.LXDZ))
                        {
                            lst.Add("txtAddress");
                        }

                        if (string.IsNullOrEmpty(info.PP))
                        {
                            lst.Add("txtPP");
                        }

                        if (string.IsNullOrEmpty(info.XH))
                        {
                            lst.Add("txtXH");
                        }

                        if (string.IsNullOrEmpty(info.FDJXH))
                        {
                            lst.Add("txtFDJXH");
                        }

                        if (string.IsNullOrEmpty(info.FDJH))
                        {
                            lst.Add("txtFDJNumber");
                        }

                        if (string.IsNullOrEmpty(info.FDJPL))
                        {
                            lst.Add("txtPL");
                        }

                        if (string.IsNullOrEmpty(info.EDZS))
                        {
                            lst.Add("txtEDZS");
                        }

                        if (string.IsNullOrEmpty(info.CCDJRQ))
                        {
                            lst.Add("txtCSDJRQ");
                        }

                        if (string.IsNullOrEmpty(info.CYS))
                        {
                            lst.Add("txtHZRS");
                        }

                        if (string.IsNullOrEmpty(info.ZZL))
                        {
                            lst.Add("txtZZL");
                        }

                        if (string.IsNullOrEmpty(info.ZBZL))
                        {
                            lst.Add("txtZBZL");
                        }

                        if (string.IsNullOrEmpty(info.CSC))
                        {
                            lst.Add("txtWKCCC");
                        }

                        if (string.IsNullOrEmpty(info.CSK))
                        {
                            lst.Add("txtWKCCK");
                        }

                        if (string.IsNullOrEmpty(info.CSG))
                        {
                            lst.Add("txtWKCCG");
                        }

                        if (string.IsNullOrEmpty(info.ZGSJCS))
                        {
                            lst.Add("txtZGSJCS");
                        }

                        if (info.RLLBDH == "A" || info.RLLBDH == "E" || info.RLLBDH == "O" )
                        {
                            if (string.IsNullOrEmpty(info.EDNJ))
                            {
                                lst.Add("txtEDNJ");
                            }
                            if (string.IsNullOrEmpty(info.EDNJZS))
                            {
                                lst.Add("txtEDNJZS");
                            }
                        }

                        if (info.RLLBDH == "B" || info.RLLBDH == "D" || info.RLLBDH == "F")
                        {
                            if (string.IsNullOrEmpty(info.EDGL))
                            {
                                lst.Add("txtEDGL");
                            }
                        }

                        if (string.IsNullOrEmpty(info.QDZKZZL))
                        {
                            lst.Add("txtQDZKZZL");
                        }

                        if (string.IsNullOrEmpty(info.YZLJ))
                        {
                            lst.Add("txtYZLJ");
                        }

                        if (string.IsNullOrEmpty(info.LJXSLC))
                        {
                            lst.Add("txtLJXSLC");
                        }

                        dicRet.Add("Z", lst);
                    }
                }
                #endregion

                #region 综检挂车
                if (string.IsNullOrEmpty(strLoginIDGC) == false)
                {
                    var infoGC = bll.GetModel(Convert.ToInt32(strLoginIDGC));
                    if (infoGC.ID > 0)
                    {
                        List<string> lst = new List<string>();
                        if (string.IsNullOrEmpty(infoGC.VIN))
                        {
                            lst.Add("txtVINGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.SYR))
                        {
                            lst.Add("txtSYRGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.LXDZ))
                        {
                            lst.Add("txtAddressGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.PP))
                        {
                            lst.Add("txtPPGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.XH))
                        {
                            lst.Add("txtXHGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.CCDJRQ))
                        {
                            lst.Add("txtCCDJRQGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.ZZL))
                        {
                            lst.Add("txtZZLGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.CSC))
                        {
                            lst.Add("txtCSCGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.CSK))
                        {
                            lst.Add("txtCSKGC");
                        }

                        if (string.IsNullOrEmpty(infoGC.CSG))
                        {
                            lst.Add("txtCSGGC");
                        }

                        dicRet.Add("ZG", lst);
                    }
                }
                #endregion
            }
            else if (strType == "P")
            {
                if (string.IsNullOrEmpty(strLoginID) == false)
                {
                    var info = bll.GetModel(Convert.ToInt32(strLoginID));
                    if (info.ID > 0)
                    {
                        List<string> lst = new List<string>();
                        if (string.IsNullOrEmpty(info.VIN))
                        {
                            lst.Add("txtVIN");
                        }

                        if (string.IsNullOrEmpty(info.LXDZ))
                        {
                            lst.Add("txtAddress");
                        }

                        if (string.IsNullOrEmpty(info.PP))
                        {
                            lst.Add("txtPP");
                        }

                        if (string.IsNullOrEmpty(info.XH))
                        {
                            lst.Add("txtXH");
                        }

                        if (string.IsNullOrEmpty(info.FDJH))
                        {
                            lst.Add("txtFDJXH");
                        }

                        if (string.IsNullOrEmpty(info.ZBZL))
                        {
                            lst.Add("txtZBZL");
                        }

                        if (string.IsNullOrEmpty(info.ZZL))
                        {
                            lst.Add("txtZZL");
                        }

                        if (string.IsNullOrEmpty(info.CYS))
                        {
                            lst.Add("txtHZRS");
                        }

                        if (string.IsNullOrEmpty(info.CPMC))
                        {
                            lst.Add("txtCPMC");
                        }

                        if (string.IsNullOrEmpty(info.CCDJRQ))
                        {
                            lst.Add("txtDJRQ");
                        }

                        if (string.IsNullOrEmpty(info.CCRQ))
                        {
                            lst.Add("txtSCRQ");
                        }

                        if (string.IsNullOrEmpty(info.EDGL))
                        {
                            lst.Add("txtEDGL");
                        }

                        if (string.IsNullOrEmpty(info.EDZS))
                        {
                            lst.Add("txtEDNJZS");
                        }

                        if (string.IsNullOrEmpty(info.FDJGS))
                        {
                            lst.Add("txtQGS");
                        }

                        dicRet.Add("P", lst);
                    }
                }
            }
            return dicRet;
        }

        /// <summary>
        /// 重置所有控件
        /// </summary>
        /// <param name="lstNames"></param>
        /// <param name="lstControls"></param>
        public static void ResetAllControls(List<ControlNames> lstNames, List<Control> lstControls)
        {
            try
            {
                for (int i = 0; i < lstNames.Count; i++)
                {
                    var con = lstControls.Where(x => x.ID == lstNames[i].Name).ToList();
                    if (con.Count > 0)
                    {
                        if (lstNames[i].Name.Substring(0, 3) == "txt")
                        {
                            try
                            {
                                TextBox txt = con[0] as TextBox;
                                txt.Text = lstNames[i].Value;
                            }
                            catch (Exception ex) { }
                        }
                        else if (lstNames[i].Name.Substring(0, 3) == "drp")
                        {
                            DropDownList drp = con[0] as DropDownList;
                            try
                            {
                                if (!string.IsNullOrEmpty(lstNames[i].Value))
                                {
                                    drp.SelectedValue = lstNames[i].Value;
                                }
                                else
                                {
                                    drp.SelectedIndex = 0;
                                }
                            }
                            catch (Exception ex) { drp.SelectedIndex = 0; }
                        }
                        else if (lstNames[i].Name.Substring(0, 4) == "rbtn")
                        {
                            try
                            {
                                RadioButtonList rbtn = con[0] as RadioButtonList;
                                rbtn.SelectedIndex = 0;
                            }
                            catch (Exception ex) { }
                        }
                        else if (lstNames[i].Name.Substring(0, 3) == "chk")
                        {
                            try
                            {
                                CheckBoxList chkList = con[0] as CheckBoxList;
                                string strValues = lstNames[i].Value;
                                if (string.IsNullOrEmpty(strValues) == false)
                                {
                                    strValues = strValues.Substring(0, strValues.Length - 1);
                                    if (strValues.Contains(","))
                                    {
                                        string[] strLst = strValues.Split(',');
                                        for (int k = 0; k < chkList.Items.Count; k++)
                                        {
                                            foreach (var s in strLst)
                                            {
                                                if (chkList.Items[k].Value == s)
                                                {
                                                    chkList.Items[k].Selected = true;
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        for (int k = 0; k < chkList.Items.Count; k++)
                                        {
                                            if (chkList.Items[k].Value == strValues)
                                            {
                                                chkList.Items[k].Selected = true;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    for (int k = 0; k < chkList.Items.Count; k++)
                                    {
                                        chkList.Items[k].Selected = false;
                                    }
                                }

                            }
                            catch (Exception ex) { }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                string strError = ex.Message;
            }
        }


        /// <summary>
        /// 检测项目更改事件调用此方法
        /// </summary>
        /// <param name="chkJYXM"></param>
        /// <param name="lstItems"></param>
        /// <param name="bFirstTest"></param>
        public static void JYXMChanged(CheckBoxList chkJYXM, List<ListItem> lstItems, bool bFirstTest, bool bIsSLQC = false)
        {
            List<string> lstSelected = new List<string>();

            for (int i = 0; i < chkJYXM.Items.Count; i++)
            {
                if (bFirstTest && bIsSLQC == false)
                {
                    if (chkJYXM.Items[i].Selected && chkJYXM.Items[i].Value.Substring(0, 1) != "Z")
                    {
                        lstSelected.Add(chkJYXM.Items[i].Value);
                    }
                }
                else
                {
                    if (chkJYXM.Items[i].Selected)
                    {
                        {
                            lstSelected.Add(chkJYXM.Items[i].Value);
                        }
                    }
                }
            }

            if (bFirstTest && bIsSLQC == false)
            {
                var cur = lstSelected.Where(x => x.Substring(0, 1) == "B" && Convert.ToInt32(x.Substring(1, 1)) > 0 && Convert.ToInt32(x.Substring(1, 1)) < 9).ToList();

                foreach (var v in cur)
                {
                    lstSelected.Add("Z" + v.Substring(1, 1).ToString());
                }
            }

            lstItems.All(x => x.Selected = false);

            foreach (var vSelected in lstSelected)
            {
                foreach (var vItem in lstItems)
                {
                    if (vSelected == vItem.Value)
                    {
                        vItem.Selected = true;
                    }
                }
            }

            for (int i = 0; i < chkJYXM.Items.Count; i++)
            {
                chkJYXM.Items[i].Selected = false;
                foreach (var v in lstSelected)
                {
                    if (chkJYXM.Items[i].Value == v)
                    {
                        chkJYXM.Items[i].Selected = true;
                    }
                }
            }
        }

        public static void CheckAll(CheckBoxList chkJYXM, bool bIsChecked)
        {
            if (bIsChecked)
            {
                for (int i = 0; i < chkJYXM.Items.Count; i++)
                {
                    chkJYXM.Items[i].Selected = true;
                }
            }
            else
            {
                for (int i = 0; i < chkJYXM.Items.Count; i++)
                {
                    chkJYXM.Items[i].Selected = false;
                }
            }
        }

        /// <summary>
        /// 绑定驻车轴位置
        /// </summary>
        /// <param name="iZZS"></param>
        /// <param name="chk"></param>
        /// <param name="chkQDZ"></param>
        public static void BindZCZWZ(int iZZS, CheckBoxList chk, CheckBoxList chkQDZ = null)
        {
            ListItem item;
            ListItem itemQDZ;
            chk.Items.Clear();
            if (chkQDZ != null)
            {
                chkQDZ.Items.Clear();
            }
            for (int i = 1; i < iZZS + 1; i++)
            {
                item = new ListItem();
                item.Text = i.ToString();
                item.Value = i.ToString();
                chk.Items.Add(item);
                if (chkQDZ != null)
                {
                    itemQDZ = new ListItem();
                    itemQDZ.Text = i.ToString();
                    itemQDZ.Value = i.ToString();
                    chkQDZ.Items.Add(itemQDZ);
                }
            }
            chk.Items[1].Selected = true;
            if (chkQDZ != null)
            {
                chkQDZ.Items[1].Selected = true;
            }
        }

        /// <summary>
        /// 判断车辆是否收费
        /// </summary>
        /// <param name="strLoginID"></param>
        /// <param name="strType"></param>
        /// <param name="bFirstTest"></param>
        /// <returns></returns>
        public static bool HasCharge(string strLoginID, string strType, bool bFirstTest)
        {
            bool b = false;
            LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();
            var info = bll.GetModel(Convert.ToInt32(strLoginID));

            CHARGE_INFO_BLL sf_bll = new CHARGE_INFO_BLL();
            string strSql = "HPHM='" + info.HPHM + "' and HPZLDH='" + info.HPZLDH + "' and (TFLSH ='' or TFLSH is null) and SFZLDH='1'";
            if (strType == "A")
            {//安检
                strSql += " and SFXM like '%AA,%' ";
            }
            else if (strType == "Z")
            {//综检
                strSql += " and SFXM like '%ZZ,%' ";
            }
            else if (strType == "P")
            {//排放
                strSql += " and SFXM like '%HH,%' ";
            }

            if (bFirstTest)
            {//初检
                strSql += " and SYBZ=0 ";
            }
            else
            {//复检
                strSql += " and SYBZ=1 ";
            }

            strSql += " order by ID desc ";

            var sfList = sf_bll.GetModelList(strSql);

            if (sfList.Length > 0)
            {
                if (bFirstTest)
                {
                    b = true;
                }
                else
                {//复检
                    VEHICLE_DISPATCH_BLL bll_DisPatch = new VEHICLE_DISPATCH_BLL();
                    var vLst = bll_DisPatch.GetModelList("VEHICLEID='" + info.VEHICLEID + "' and subString(JCLSH,1,1)='" + strType + "' order by ID desc");
                    DateTime dtFisrtOnline;
                    if (vLst.Length > 0)
                    {//复检有记录
                        RESULT_VEHICLE_INFO_BLL result_bll = new RESULT_VEHICLE_INFO_BLL();
                        dtFisrtOnline = Convert.ToDateTime(result_bll.GetModel(GetAllJCLSH(vLst[0].JCLSH)[0]).JCRQ);

                        CONST_DEFINE_WEB_BLL con_bll = new CONST_DEFINE_WEB_BLL();
                        var con = con_bll.GetModelList("CategoryID=3");
                        if (con.Length > 0)
                        {
                            if (dtFisrtOnline.AddMonths(Convert.ToInt32(con[0].ValueOfName)) > DateTime.Now)
                            {
                                b = false;
                            }
                            else
                            {
                                b = true;
                            }
                        }
                    }
                    else
                    {
                        b = false;
                    }

                }
            }
            else
            {
                b = false;
            }

            return b;
        }

        /// <summary>
        /// 根据传入的检测流水号，得到之前所有的检测流水号
        /// </summary>
        /// <param name="strJCLSH"></param>
        /// <returns></returns>
        public static List<string> GetAllJCLSH(string strJCLSH)
        {
            List<string> lstJCLSH = new List<string>();
            if (strJCLSH.Contains("-"))
            {
                string[] strInfos = strJCLSH.Split('-');
                int iJCCS = Convert.ToInt32(strInfos[1]) + 1;
                for (int i = 1; i < iJCCS; i++)
                {
                    lstJCLSH.Add(strInfos[0] + "-" + i.ToString("d2"));
                }
            }
            else
            {
                lstJCLSH.Add(strJCLSH);
            }

            return lstJCLSH;
        }

        /// <summary>
        /// 保存品牌型号和发动机信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static bool SavePPXHAndFDJXH(LOGIN_VEHICLE_INFO info)
        {
            bool b = false;

            try
            {
                TYPE_CX_CONTENT_BLL pp_bll = new TYPE_CX_CONTENT_BLL();
                TYPE_CX_CONTENT pp = new TYPE_CX_CONTENT();

                #region 品牌型号
                if (!string.IsNullOrEmpty(info.PP))
                {
                    pp.PP = info.PP;
                }

                if (!string.IsNullOrEmpty(info.XH))
                {
                    pp.XH = info.XH;
                }

                if (!string.IsNullOrEmpty(info.PPXH))
                {
                    pp.PPXH = info.PPXH;
                }

                if (!string.IsNullOrEmpty(info.QDXS))
                {
                    pp.QDXS = info.QDXS;
                }

                if (!string.IsNullOrEmpty(info.ZCZWZ))
                {
                    pp.ZCZWZ = info.ZCZWZ;
                }

                if (!string.IsNullOrEmpty(info.QDZWZ))
                {
                    pp.QDZWZ = info.QDZWZ;
                }

                if (!string.IsNullOrEmpty(info.QZDZDH))
                {
                    pp.QZDZ = info.QZDZDH;
                }

                if (!string.IsNullOrEmpty(info.ZBZL))
                {
                    pp.ZBZL = info.ZBZL;
                }

                if (!string.IsNullOrEmpty(info.ZZL))
                {
                    pp.ZZL = info.ZZL;
                }

                if (!string.IsNullOrEmpty(info.HDZH))
                {
                    pp.HDZH = info.HDZH;
                }

                if (!string.IsNullOrEmpty(info.ZZS))
                {
                    pp.ZZS = info.ZZS;
                }

                if (!string.IsNullOrEmpty(info.CYS))
                {
                    pp.CYS = info.CYS;
                }

                if (!string.IsNullOrEmpty(info.ZGSJCS))
                {
                    pp.ZGSJCS = info.ZGSJCS;
                }

                if (!string.IsNullOrEmpty(info.ZDFS))
                {
                    pp.ZDFS = info.ZDFS;
                }

                if (!string.IsNullOrEmpty(info.CLZLDH))
                {
                    pp.CLZL = info.CLZLDH;
                }

                if (!string.IsNullOrEmpty(info.ZXZXJXSDH))
                {
                    pp.ZXZXJXS = info.ZXZXJXSDH;
                }

                if (!string.IsNullOrEmpty(info.ZXZLXDH))
                {
                    pp.ZXZLX = info.ZXZLXDH;
                }

                if (!string.IsNullOrEmpty(info.BSXLXDH))
                {
                    pp.BSXLX = info.BSXLXDH;
                }

                if (!string.IsNullOrEmpty(info.LTQY))
                {
                    pp.LTQY = info.LTQY;
                }

                if (!string.IsNullOrEmpty(info.LTGG))
                {
                    pp.LTGG = info.LTGG;
                }

                if (!string.IsNullOrEmpty(info.LTGGLXDH))
                {
                    pp.LTGGLX = info.LTGGLXDH;
                }

                if (!string.IsNullOrEmpty(info.LTSL))
                {
                    pp.LTSL = info.LTSL;
                }

                if (!string.IsNullOrEmpty(info.CSC))
                {
                    pp.CSC = info.CSC;
                }

                if (!string.IsNullOrEmpty(info.CSK))
                {
                    pp.CSK = info.CSK;
                }

                if (!string.IsNullOrEmpty(info.CSG))
                {
                    pp.CSG = info.CSG;
                }


                if (!string.IsNullOrEmpty(info.ZJ))
                {
                    pp.ZJ = info.ZJ;
                }

                if (!string.IsNullOrEmpty(info.BZZXS))
                {
                    pp.BZZXS = info.BZZXS;
                }

                if (!string.IsNullOrEmpty(info.YHSD))
                {
                    pp.YHSD = info.YHSD;
                }

                if (!string.IsNullOrEmpty(info.YHXZ))
                {
                    pp.YHXZ = info.YHXZ;
                }

                if (!string.IsNullOrEmpty(info.YDXZ))
                {
                    pp.YDXZ = info.YDXZ;
                }

                var vInfo = pp_bll.GetModelList("PP='" + pp.PP + "' and XH='" + pp.XH + "' order by ID desc");
                if (vInfo.Length > 0)
                {
                    //pp_bll.Update(pp, vInfo[0].ID);
                }
                else
                {
                    pp_bll.Insert(pp);
                }

                TYPE_CX_FDJ_UNION_BLL pp_fdj_bll = new TYPE_CX_FDJ_UNION_BLL();
                var CX_FDJ = pp_fdj_bll.GetModelList("PP='" + pp.PP + "' and XH='" + pp.XH + "' and FDJXH='" + info.FDJXH + "' order by ID desc");
                if (CX_FDJ.Length == 0)
                {
                    TYPE_CX_FDJ_UNION union = new TYPE_CX_FDJ_UNION();
                    union.FDJXH = info.FDJXH;
                    union.PP = info.PP;
                    union.XH = info.XH;
                    union.PPXH = info.PPXH;
                    union.PPZM = SpellCode.GetSpellCode(info.PP);
                    pp_fdj_bll.Insert(union);
                }

                TYPE_FDJ_CONTENT_BLL fdj_bll = new TYPE_FDJ_CONTENT_BLL();
                var FDJ_Lst = fdj_bll.GetModelList("FDJXH='" + info.FDJXH + "'");

                TYPE_FDJ_CONTENT fdj = new TYPE_FDJ_CONTENT();

                if (!string.IsNullOrEmpty(info.FDJXH))
                {
                    fdj.FDJXH = info.FDJXH;
                }

                if (!string.IsNullOrEmpty(info.FDJZZCS))
                {
                    fdj.FDJZZC = info.FDJZZCS;
                }

                if (!string.IsNullOrEmpty(info.RLLBDH))
                {
                    fdj.RLLB = info.RLLBDH;
                }

                if (!string.IsNullOrEmpty(info.RYBH))
                {
                    fdj.RYBH = info.RYBH;
                }

                if (!string.IsNullOrEmpty(info.GYFSDH))
                {
                    fdj.GYFS = info.GYFSDH;
                }

                if (!string.IsNullOrEmpty(info.JQFSDH))
                {
                    fdj.JQFS = info.JQFSDH;
                }

                if (!string.IsNullOrEmpty(info.EDGL))
                {
                    fdj.EDGL = info.EDGL;
                }

                if (!string.IsNullOrEmpty(info.EDZS))
                {
                    fdj.EDZS = info.EDZS;
                }

                if (!string.IsNullOrEmpty(info.EDNJZS))
                {
                    fdj.EDNJZS = info.EDNJZS;
                }

                if (!string.IsNullOrEmpty(info.EDNJ))
                {
                    fdj.EDNJ = info.EDNJ;
                }

                if (!string.IsNullOrEmpty(info.EDYH))
                {
                    fdj.EDYH = info.EDYH;
                }

                if (!string.IsNullOrEmpty(info.FDJPL))
                {
                    fdj.FDJPL = info.FDJPL;
                }

                if (!string.IsNullOrEmpty(info.FDJGS))
                {
                    fdj.FDJGS = info.FDJGS;
                }

                if (!string.IsNullOrEmpty(info.FDJCC))
                {
                    fdj.FDJCC = info.FDJCC;
                }

                if (FDJ_Lst.Length > 0)
                {
                    //fdj_bll.Update(fdj, FDJ_Lst[0].ID);
                }
                else
                {
                    fdj_bll.Insert(fdj);
                }

                #endregion

                b = true;
            }
            catch (Exception ex)
            {
                b = false;
            }


            return b;
        }

        public static string GetLoginedUserName()
        {
            string strUserName = "";
            if (HttpContext.Current.Session["UserName"] != null && HttpContext.Current.Session["UserName"].ToString() != "")
            {
                string userName = HttpContext.Current.Session["UserName"].ToString();
                strUserName = IYAKASAPortal.Services.UserAuthority.GetUserAuthority(userName).UserName;
            }

            return strUserName;
        }

        public static bool isHPHM(string hphm)
        {
            bool result = false;
            if (hphm.Length == 7)
            {
                string express = @"^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$";
                result = Regex.IsMatch(hphm, express);
            }
            return result;
        }

        /// <summary>
        /// 重置所有控件颜色
        /// </summary>
        public static void ResetAllValidate(Type t, object obj)
        {
            FieldInfo[] infos = t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
            for (int i = 0; i < infos.Length; i++)
            {
                if (infos[i].FieldType == typeof(TextBox))
                {
                    TextBox txt = ((TextBox)infos[i].GetValue(obj));
                    if (txt.ReadOnly == false)
                    {
                        txt.BackColor = Color.White;
                    }

                }
            }
        }


        public static void BindTemplate(string strType, RadioButtonList rbtn, CheckBoxList chkJYXM, List<ListItem> lstItems)
        {
            CONST_DEFINE_WEB_BLL bll = new CONST_DEFINE_WEB_BLL();
            string strItem = "";
            if (strType == "A")
            {
                strItem = "10";
            }
            else if (strType == "Z")
            {
                strItem = "6";
            }
            else if (strType == "ZG")
            {
                strItem = "7";
            }
            var infos = bll.GetModelList("CategoryID='" + strItem + "' and ValueOfName='" + rbtn.SelectedValue + "'");

            if (infos.Length > 0)
            {
                string strValue = infos[0].Remark;
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    strValue = strValue.Substring(0, strValue.Length - 1);
                    string[] items = strValue.Split(',');
                    lstItems.All(x => x.Selected = false);
                    foreach (var v in items)
                    {
                        foreach (var vItem in lstItems)
                        {
                            if (vItem.Value == v)
                            {
                                vItem.Selected = true;
                            }
                        }
                    }

                    for (int i = 0; i < chkJYXM.Items.Count; i++)
                    {
                        chkJYXM.Items[i].Selected = false;
                        foreach (var v in items)
                        {
                            if (chkJYXM.Items[i].Value == v)
                            {
                                chkJYXM.Items[i].Selected = true;
                            }
                        }
                    }
                }
                else
                {
                    lstItems.All(x => x.Selected = false);
                    for (int i = 0; i < chkJYXM.Items.Count; i++)
                    {
                        chkJYXM.Items[i].Selected = false;
                    }
                }
            }
        }
    }
}